{extend name="public/base"}

{block name="css"}
<style>
    .layui-upload-img {
        width: 170px;
        height: 96px;
        margin: 0 10px 10px 0;
    }
</style>
{/block}

{block name="main"}
<div class="layui-card">
    <form class="layui-form" action="" lay-filter="component-form-group">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
            <legend>基本信息</legend>
        </fieldset>
        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-inline">
                <input type="text" lay-verify="required" placeholder="请输入"
                       autocomplete="off"
                       class="layui-input"  name="name" value="{$data.name|default=''}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">上级分类</label>
            <div class="layui-input-inline">
                <select name="pid">
                    <option value="">请选择</option>
                    {volist name="cates" id="vo"}
                    <option value="{$vo.id}" {eq name="data.pid|default=0" value="$vo.id"}selected{/eq}>{$vo.name}</option>
                    {/volist}
                </select>
            </div>
        </div>

        <div class="layui-form-item layui-layout-admin">
            <div class="layui-input-block">
                <div class="layui-footer" style="left: 0;">
                    <input type="hidden" name="id" value="{$data.id|default=0}">
                    <button class="layui-btn" lay-submit="" lay-filter="component-form-demo1">立即提交</button>
                </div>
            </div>
        </div>

    </form>
</div>
{/block}

{block name="js"}
<script>
    layui.config({
        base: '/layui_admin/src/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function () {
        let $ = layui.$
            , form = layui.form, admin = layui.admin, layer = layui.layer;

        /* 监听提交 */
        form.on('submit(component-form-demo1)', function (data) {
            layer.load();
            //请求登入接口
            admin.req({
                url: "{:url('save_category')}" //实际使用请改成服务端真实接口
                ,type : 'post'
                ,data: data.field
                ,done: function(res){
                    //登入成功的提示与跳转
                    layer.msg('保存成功', {
                        offset: '15px'
                        ,icon: 1
                        ,time: 1000
                    }, function(){
                        parent.location.reload(); //刷新页面
                    });
                }
            });
            return false;
        });
    });
</script>
{/block}